package cn.jiedh.app.meiweidk.loan;

import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bigkoo.pickerview.OptionsPickerView;
import com.bumptech.glide.Glide;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.umeng.analytics.MobclickAgent;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import org.xutils.ex.HttpException;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;

import butterknife.BindView;
import butterknife.OnClick;
import cn.jiedh.app.meiweidk.MainActivity;
import cn.jiedh.app.meiweidk.MyWebActivity;
import cn.jiedh.app.meiweidk.R;
import cn.jiedh.app.meiweidk.Utils.UI.AlertDialog;
import cn.jiedh.app.meiweidk.Utils.UI.ObservableScrollView;
import cn.jiedh.app.meiweidk.Utils.tool.ActivityUtil;
import cn.jiedh.app.meiweidk.Utils.tool.L;
import cn.jiedh.app.meiweidk.Utils.tool.LoadUtils;
import cn.jiedh.app.meiweidk.Utils.tool.NumUtils;
import cn.jiedh.app.meiweidk.Utils.tool.SPUtils;
import cn.jiedh.app.meiweidk.Utils.tool.T;
import cn.jiedh.app.meiweidk.Utils.tool.UrlUtils;
import cn.jiedh.app.meiweidk.base.BaseActivity;
import cn.jiedh.app.meiweidk.buried.BuriedBean;
import cn.jiedh.app.meiweidk.entity.ApplicationInfoBean;
import cn.jiedh.app.meiweidk.entity.LoanDetailBean;
import cn.jiedh.app.meiweidk.entity.SurveyBean;
import cn.jiedh.app.meiweidk.entity.productLinkTransferBean;
import cn.jiedh.app.meiweidk.homepage.NewProductData;
import cn.jiedh.app.meiweidk.login.LoginActivity;
import cn.jiedh.app.meiweidk.network.ResponseFailure;
import cn.jiedh.app.meiweidk.network.ResponseSuccess;
import cn.jiedh.app.meiweidk.response.BaseResponse;
import cn.jiedh.app.meiweidk.survey.SurveyActivity;


/**
 * @name：产品详情
 * @author：司马林
 * @phone：18423134135
 * @createTime：2017/10/23
 */

public class LoanDetailActivity extends BaseActivity implements ObservableScrollView.OnObservableScrollViewScrollChanged {
    @BindView(R.id.bar_tv_title)
    TextView title;
    @BindView(R.id.sv_contentView)
    ObservableScrollView svContentView;
    @BindView(R.id.top_layout)
    LinearLayout topLayout;
    @BindView(R.id.loan_detail_tab)
    TabLayout tabLayout;
    @BindView(R.id.ll_fixedView)
    LinearLayout ll_fixedView;
    @BindView(R.id.loan_detail_icon)
    ImageView loanDetailIconImg;
    @BindView(R.id.loan_detail_title)
    TextView loanDetailTitleTv;
    @BindView(R.id.loan_detail_advert)
    TextView loanDetailAdvertTv;
    @BindView(R.id.num_of_applicants)
    TextView numOfApplicantsTv;
    @BindView(R.id.fastest_lender_time)
    TextView fastestLenderTimeTv;
    @BindView(R.id.success_rate)
    TextView successRateTv;
    @BindView(R.id.loan_detail_advert_img_one)
    ImageView loanDetailAdvertOneImg;
    @BindView(R.id.loan_detail_advert_img_two)
    ImageView loanDetailAdvertTwoImg;
    @BindView(R.id.quota)
    TextView quotaTv;
    @BindView(R.id.term)
    TextView termTv;
    @BindView(R.id.interest)
    TextView interestTv;
    @BindView(R.id.interest_rate)
    TextView interestRateTv;
    @BindView(R.id.quota_section)
    TextView quotaSectionTv;
    @BindView(R.id.term_section)
    TextView termSectionTv;
    @BindView(R.id.rate_type_tv)
    TextView rateTypeTv;
    @BindView(R.id.add_comment)
    FloatingActionButton addComment;
    @BindView(R.id.refresh_layout)
    SmartRefreshLayout refreshLayout;
    @BindView(R.id.id_flowlayout)
    TagFlowLayout flowLayout;

    private boolean isFromeBrowse;//是否是从我的浏览进入这个页面

    private OptionsPickerView termPickerView;
    private OptionsPickerView quotaPickerView;
    private List<String> termPickerList = new ArrayList<>();
    private List<String> quotaPickerList = new ArrayList<>();

    private List<LoanDetailBean.AdverList> advertList = new ArrayList<>();

    //用来记录内层固定布局到屏幕顶部的距离
    private int mHeight;
    private int productId;

    private int quota;//用户所选金额
    private int term;//用户所选期限
    private int rateType;//利率类型  1：月利率  2：日利率
    private double rate;
    private LoanDetailBean bean;

    private String iconUrl;
    private String loanTitle;
    private String loanAdvert;
    private String applyUrl;

    private FragmentTransaction ft;

    private List<BuriedBean> buriedList;
    private String selectMoney;
    private String selectTerm;
    private String interestRate;

    private int dialogNum;

    @Override
    protected int getLayoutView() {
        return R.layout.activity_loan_detail;
    }

    @Override
    protected void initView(View view) {

        svContentView.setOnObservableScrollViewScrollChanged(this);
        if (getIntent() != null) {
            productId = getIntent().getExtras().getInt("productId");
            title.setText("贷款详情");
            isFromeBrowse = getIntent().getExtras().getBoolean("fromeBrowse");
            collect("19",productId+"",null);
        }

        quotaPickerView = new OptionsPickerView.Builder(this, (options1, options2, options3, v) -> {
            String quotaStr = quotaPickerList.get(options1);
            quota = Integer.parseInt(quotaStr.substring(0, quotaStr.indexOf("元")));
            quotaTv.setText(quotaStr);
            selectMoney = quotaStr;
            interestTv.setText(NumUtils.getTwoDecimal(((quota * term * rate) / 100)) + "元");
        }).setOutSideCancelable(false)
                .setDividerColor(R.color.hint3_text_color)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();

        termPickerView = new OptionsPickerView.Builder(this, (options1, options2, options3, v) -> {
            String termStr = termPickerList.get(options1);
            selectTerm = termStr;
            if (1 == rateType) {
                term = Integer.valueOf(termStr.substring(0, termStr.indexOf("月")));
            } else if (2 == rateType) {
                term = Integer.valueOf(termStr.substring(0, termStr.indexOf("天")));
            }
            termTv.setText(termStr);
            interestTv.setText(NumUtils.getTwoDecimal(((quota * term * rate) / 100)) + "元");
        }).setOutSideCancelable(false)
                .setDividerColor(R.color.hint3_text_color)
                .setTextColorCenter(Color.BLACK) //设置选中项文字颜色
                .setContentTextSize(20)
                .build();

        refreshLayout.setOnRefreshListener(refreshLayout -> refreshLayout.getLayout().postDelayed(() -> {
            initData();
            refreshLayout.finishRefresh();
            refreshLayout.setLoadmoreFinished(false);
        }, 2000));
        tabLayout.addTab(tabLayout.newTab().setText("产品详情"));
        tabLayout.addTab(tabLayout.newTab().setText("用户评价(0)"));
    }

    private void initTabLayout() {
        ft = getSupportFragmentManager().beginTransaction();
        Fragment loanDetailInfoFragment = new LoanDetailInfoFragment();
        Bundle bundle = new Bundle();
        if (bean != null) {
            bundle.putSerializable("detail", bean);
        }
        loanDetailInfoFragment.setArguments(bundle);
        ft.replace(R.id.loan_detail_frame_layout, loanDetailInfoFragment).commit();
        tabLayout.getTabAt(0).select();

        tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                if ("产品详情".equals(tab.getText())) {
                    MobclickAgent.onEvent(activity, "productdetail"); //umeng
                    addComment.setVisibility(View.GONE);
                    ft = getSupportFragmentManager().beginTransaction();
                    ft.replace(R.id.loan_detail_frame_layout, loanDetailInfoFragment).commit();
                } else {
                    MobclickAgent.onEvent(activity, "evaluate"); //umeng
                    addComment.setVisibility(View.VISIBLE);
                    Fragment loanDetailCommentFragment = new LoanDetailCommentFragment();
                    Bundle bundle = new Bundle();
                    bundle.putInt("productId", productId);
                    bundle.putString("iconUrl", iconUrl);
                    bundle.putString("loanTitle", loanTitle);
                    bundle.putString("loanAdvert", loanAdvert);
                    loanDetailCommentFragment.setArguments(bundle);
                    ft = getSupportFragmentManager().beginTransaction();
                    ft.replace(R.id.loan_detail_frame_layout, loanDetailCommentFragment).commit();
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @OnClick({R.id.quota_layout, R.id.term_layout, R.id.apply, R.id.loan_detail_advert_img_one, R.id.loan_detail_advert_img_two, R.id.add_comment})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.quota_layout:
                if (quotaPickerView != null) {
                    quotaPickerView.show();
                }
                break;
            case R.id.term_layout:
                if (termPickerView != null) {
                    termPickerView.show();
                }
                break;
            case R.id.apply:
                MobclickAgent.onEvent(activity, "Apply_now"); //umeng
                buriedList = new ArrayList<>();
                buriedList.add(new BuriedBean("apply", "申请贷款按钮入口", "0", "", "申请贷款", "", "false", "", "", "", "", "", selectMoney, selectTerm, "", interestRate, ""));
                SPUtils.saveBuriedList(buriedList);
                if (SPUtils.getIsLogin()) {
                    apply(productId);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("isGoHome",true);
                    ActivityUtil.next(this, LoginActivity.class,bundle);
                }
                break;
            case R.id.loan_detail_advert_img_one:
                buriedList = new ArrayList<>();
                buriedList.add(new BuriedBean("click", "贷款详情-第一个广告位", "2", "", advertList.get(0).getName(), "贷款详情", "false", "", "", "", "", "", "", "", "", "", ""));
                SPUtils.saveBuriedList(buriedList);
                MobclickAgent.onEvent(activity, "product_deteal_adver1");
                String advertOneName = advertList.get(0).getName();
                String advertOneUrl = advertList.get(0).getAdverUrl();
                Bundle advertOneBundle = new Bundle();
                advertOneBundle.putString("url", advertOneUrl);
                advertOneBundle.putString("title", advertOneName);
                if (!TextUtils.isEmpty(advertOneUrl)) {
                    ActivityUtil.next(this, MyWebActivity.class, advertOneBundle);
//                    collect("13",null,advertOneUrl);
                }
                break;
            case R.id.loan_detail_advert_img_two:
                buriedList = new ArrayList<>();
                buriedList.add(new BuriedBean("click", "贷款详情-第二个广告位", "2", "", advertList.get(1).getName(), "贷款详情", "false", "", "", "", "", "", "", "", "", "", ""));
                SPUtils.saveBuriedList(buriedList);
                MobclickAgent.onEvent(activity, "product_deteal_adver2");
                String advertTwoName = advertList.get(1).getName();
                String advertTwoUrl = advertList.get(1).getAdverUrl();
                Bundle advertTwoBundle = new Bundle();
                advertTwoBundle.putString("url", advertTwoUrl);
                advertTwoBundle.putString("title", advertTwoName);
                if (!TextUtils.isEmpty(advertTwoUrl)) {
                    ActivityUtil.next(this, MyWebActivity.class, advertTwoBundle);
//                    collect("14",null,advertTwoUrl);
                }
                break;
            case R.id.add_comment:
                MobclickAgent.onEvent(activity,"loanDetail_command");
                MobclickAgent.onEvent(activity, "click_evaluate");
                SPUtils.saveBuried("click", "0", "贷款详情-评价按钮", "",
                        "贷款详情", "", "", productId + "");
                if (SPUtils.getIsLogin()) {
                    Bundle bundle = new Bundle();
                    bundle.putInt("productId", productId);
                    bundle.putString("iconUrl", iconUrl);
                    bundle.putString("loanTitle", loanTitle);
                    bundle.putString("loanAdvert", loanAdvert);
                    ActivityUtil.next(this, AddCommentsActivity.class, bundle);
                } else {
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("isGoHome",true);
                    ActivityUtil.next(this, LoginActivity.class,bundle);
                }
                break;
            default:
                break;
        }
    }

    @Override
    protected void initData() {
        showLoadingDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("productId", productId);
        request(this, UrlUtils.PRODUCTINFO, map, false, new ResponseSuccess<LoanDetailBean>() {
            @Override
            public void onRequestSucceed(BaseResponse<LoanDetailBean> response) {
                dismissLoadingDialog();
                if (0 == response.getCode()) {
                    bean = response.getData();
                    quota = (int) response.getData().getMoneyMax();
                    term = response.getData().getTermMax();
                    rate = response.getData().getRate();
                    applyUrl = response.getData().getApplyUrl();
                    rateType = response.getData().getRateType();
                    iconUrl = response.getData().getImgUrl();
                    loanTitle = response.getData().getName();
                    loanAdvert = response.getData().getAdver();

                    LoadUtils.loadImage(LoanDetailActivity.this,iconUrl,loanDetailIconImg);

                    loanDetailTitleTv.setText(loanTitle);
                    loanDetailAdvertTv.setText(loanAdvert);
                    advertList.addAll(response.getData().getAdverList());
                    if (0 == advertList.size()) {
                        loanDetailAdvertOneImg.setVisibility(View.GONE);
                        loanDetailAdvertTwoImg.setVisibility(View.GONE);
                    } else if (1 == advertList.size()) {
                        loanDetailAdvertOneImg.setVisibility(View.VISIBLE);
                        LoadUtils.loadImage(LoanDetailActivity.this,advertList.get(0).getImgUrl(),loanDetailAdvertOneImg);
//                        Glide.with(LoanDetailActivity.this).load(advertList.get(0).getImgUrl()).placeholder(R.drawable.green_loading).error(R.drawable.load_fail).into();
                        loanDetailAdvertTwoImg.setVisibility(View.GONE);
                    } else if (2 == advertList.size()) {
                        loanDetailAdvertOneImg.setVisibility(View.VISIBLE);
                        LoadUtils.loadImage(LoanDetailActivity.this,advertList.get(0).getImgUrl(),loanDetailAdvertOneImg);
                        loanDetailAdvertTwoImg.setVisibility(View.VISIBLE);
                        LoadUtils.loadImage(LoanDetailActivity.this,advertList.get(1).getImgUrl(),loanDetailAdvertTwoImg);
//                        Glide.with(LoanDetailActivity.this).load(advertList.get(1).getImgUrl()).placeholder(R.drawable.green_loading).error(R.drawable.load_fail).into(loanDetailAdvertTwoImg);
                    }
                    flowLayout.setAdapter(new TagAdapter<String>(response.getData().getLoanTyprList()) {
                        @Override
                        public View getView(FlowLayout parent, int position, String o) {
                            TextView tv = (TextView) LayoutInflater.from(LoanDetailActivity.this).inflate(R.layout.detail_advert_item, flowLayout, false);
                            tv.setText(o);
                            return tv;
                        }
                    });
                    numOfApplicantsTv.setText(response.getData().getApplyPeople() + "");
                    fastestLenderTimeTv.setText(response.getData().getLoanTime() + "分钟");
                    successRateTv.setText((int) response.getData().getSuccessRate() + "%");
                    quotaSectionTv.setText("额度（" + (int) response.getData().getMoneyMin() + "-" + (int) response.getData().getMoneyMax() + "元）");
                    if (1 == rateType) {
                        rateTypeTv.setText("月利率");
                        termSectionTv.setText("期限（" + response.getData().getTermMin() + "-" + response.getData().getTermMax() + "月）");
                        termTv.setText(term + "月");
                    } else if (2 == rateType) {
                        rateTypeTv.setText("日利率");
                        termSectionTv.setText("期限（" + response.getData().getTermMin() + "-" + response.getData().getTermMax() + "天）");
                        termTv.setText(term + "天");
                    }
                    interestRateTv.setText(response.getData().getRate() + "%");
                    interestRate = response.getData().getRate() + "";
                    quotaTv.setText(quota + "元");
                    interestTv.setText(NumUtils.getTwoDecimal(((quota * term * rate) / 100)) + "元");

                    int moneyItem = (int) response.getData().getMoneyMin();
                    for (; moneyItem < (int) response.getData().getMoneyMax(); ) {
                        quotaPickerList.add(moneyItem + "元");
                        moneyItem += (response.getData().getMoneyIncreasing());
                    }
                    quotaPickerList.add((int) (response.getData().getMoneyMax()) + "元");
                    quotaPickerView.setPicker(quotaPickerList);

                    int termItem = response.getData().getTermMin();
                    for (; termItem < response.getData().getTermMax(); ) {
                        if (1 == rateType) {
                            termPickerList.add(termItem + "月");
                        } else if (2 == rateType) {
                            termPickerList.add(termItem + "天");
                        }
                        termItem += response.getData().getTermIncreasing();
                    }
                    if (1 == rateType) {
                        termPickerList.add(response.getData().getTermMax() + "月");
                    } else if (2 == rateType) {
                        termPickerList.add(response.getData().getTermMax() + "天");
                    }
                    termPickerView.setPicker(termPickerList);
                    tabLayout.getTabAt(1).setText("用户评价(" + response.getData().getCommentTotal() + ")");
                    initTabLayout();

                    findViewById(R.id.error_layout).setVisibility(View.GONE);
                    findViewById(R.id.detail_layout).setVisibility(View.VISIBLE);
                } else if (1 == response.getCode()) {
                    findViewById(R.id.error_layout).setVisibility(View.VISIBLE);
                    findViewById(R.id.detail_layout).setVisibility(View.GONE);
                }
            }
        }, (error, msg) -> {
            findViewById(R.id.error_layout).setVisibility(View.VISIBLE);
            findViewById(R.id.detail_layout).setVisibility(View.GONE);
            L.e(msg);
        });
    }

    private void apply(int productId) {
        showLoadingDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("productId", productId+"");
        request(this, UrlUtils.ADDBROWSE, map, false, response -> {
            dismissLoadingDialog();
            if (0 == response.getCode()) {
                productLinkTransfer(productId,applyUrl,loanTitle);
            } else {
                T.showShort(response.getMessage());
            }
        });
    }



    /**
     * 是否是联合登陆的产品
     */
    private void productLinkTransfer(int productId,String applyUrl,String loanTitle){
        showLoadingDialog();
        Map<String, Object> map = new HashMap<>();
        map.put("productId", productId + "");
        request(UrlUtils.PRODUCT_LINK_TRANSFER, map, false, new ResponseSuccess<productLinkTransferBean>() {
            @Override
            public void onRequestSucceed(BaseResponse<productLinkTransferBean> response) {
                dismissLoadingDialog();
                Intent intent = new Intent(LoanDetailActivity.this, MyWebActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("title", loanTitle);
                if (0 == response.getCode()) {
                    bundle.putString("url", response.getData().getApplyUrl());
                } else {
                    bundle.putString("url", applyUrl);
                }
                intent.putExtras(bundle);
                startActivityForResult(intent, 1);
            }
        }, new ResponseFailure() {
            @Override
            public void onRequestFailure(HttpException error, String msg) {
                T.show(msg);
                dismissLoadingDialog();
            }
        });
    }


    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            //获取HeaderView的高度，当滑动大于等于这个高度的时候，需要把topView移除当前布局，放入到外层布局
            mHeight = topLayout.getTop();
        }
    }

    @Override
    public void onObservableScrollViewScrollChanged(int l, int t, int oldL, int oldT) {
        if (t >= mHeight) {
            if (tabLayout.getParent() != ll_fixedView) {
                topLayout.removeView(tabLayout);
                ll_fixedView.addView(tabLayout, 0);
            }
        } else {
            if (tabLayout.getParent() != topLayout) {
                ll_fixedView.removeView(tabLayout);
                topLayout.addView(tabLayout, 0);
            }
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == MyWebActivity.LOAN_DETAIL_RESULT) {
            int time = data.getIntExtra("time", 0);
            buriedList = new ArrayList<>();
            buriedList.add(new BuriedBean("stay", "", "9", "", loanTitle, loanTitle, "true", time + "", "", "", "", "", "", "", "", "", ""));
            SPUtils.saveBuriedList(buriedList);
            ApplicationInfoBean bean = SPUtils.getAppInfoFromSP();
            L.e("bombBoxNum", bean.getBombBoxNum() + "");
            L.e("dialogNum", SPUtils.getFromApp(this, "dialogNum", 0) + "");
            dialogNum = (int) SPUtils.getFromApp(this, "dialogNum", 0);
            if (time >= bean.getQuestionnaireTime()) {
                Map map = new HashMap<String, Objects>();
                map.put("priductId", productId);
                request(this, UrlUtils.SURVEYGET, map, false, new ResponseSuccess<SurveyBean>() {
                    @Override
                    public void onRequestSucceed(BaseResponse<SurveyBean> response) {
                        //当code = 0的时候才进入调查问卷页面
                        if (response.getCode() == 0) {
                            MobclickAgent.onEvent(activity,"wenjuan");
                            Bundle bundle = new Bundle();
                            bundle.putSerializable("surveyBean", response.getData());
                            bundle.putInt("productId", productId);
                            ActivityUtil.next(LoanDetailActivity.this, SurveyActivity.class, bundle);
                        } else if (dialogNum > 0) {
                            showDialog();
                        }
                    }
                });
            } else if (dialogNum > 0) {
                showDialog();
            }
        } else if (resultCode == SurveyActivity.SUVEYRESULT) {
            int time = data.getIntExtra("stayTime", 0);
            buriedList = new ArrayList<>();
            buriedList.add(new BuriedBean("stay", "调查问卷停留时间", "8", "", "调查问卷停留时间", "调查问卷", "false", time + "", "", "", "", "", "", "", "", "", ""));
            SPUtils.saveBuriedList(buriedList);
        }
    }

    private void showDialog() {
        dialogNum = dialogNum - 1;
        SPUtils.saveToApp(this, "dialogNum", dialogNum);
        AlertDialog dialog = new AlertDialog(this).builder().setMsg("想看看其他好的产品？")
                .setNegativeButton("考虑一下", v -> {
                    buriedList = new ArrayList<BuriedBean>();
                    buriedList.add(new BuriedBean("click", "贷款详情-弹出窗-按钮-考虑一下", "0", "", "", "贷款详情", "false", "", "", "", "", "", "", "", "", "", ""));
                    SPUtils.saveBuriedList(buriedList);
                    MobclickAgent.onEvent(activity, "close_window");
                }).setPositiveButton("带我去吧！", v -> {
                    buriedList = new ArrayList<BuriedBean>();
                    buriedList.add(new BuriedBean("click", "贷款详情-弹出窗-按钮-带我去吧", "0", "", "", "贷款详情", "false", "", "", "", "", "", "", "", "", "", ""));
                    SPUtils.saveBuriedList(buriedList);
                    MobclickAgent.onEvent(activity, "more_product");
                    Bundle bundle = new Bundle();
                    bundle.putBoolean("isGoLoanList", true);
                    ActivityUtil.next(LoanDetailActivity.this, MainActivity.class, bundle);
                });
        dialog.show();
    }

    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("产品详情页面");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        MobclickAgent.onPageEnd("产品详情页面");
        MobclickAgent.onPause(this);
        super.onPause();
    }

    /**
     * 功能统计
     *
     * @param type      类型
     * @param collectId type为0和19时collectId不为空
     * @param url       有就传
     */
    private void collect(String type, String collectId, String url) {
        Map<String, Object> map = new HashMap<>();
        map.put("type", type);
        if (null != collectId) {
            map.put("collectId", collectId);
        }
        if (null != url) {
            map.put("url", url);
        }
        request(UrlUtils.COLLECT, map, true, new ResponseSuccess<NewProductData>() {
            @Override
            public void onRequestSucceed(BaseResponse<NewProductData> response) {
            }
        });
    }

}
